import {call, put} from 'redux-saga/effects';
import {requestUserLogin} from "../request/userLogin";
import {setActiveUser} from "../../reducers/userLogin";


export function* handleUserLogin(action) {
  try {
    const response = yield call(requestUserLogin, action);
    const {data} = response;
    yield put(setActiveUser());
    localStorage.setItem("userToken", data.token);
    localStorage.setItem("openlapUser", JSON.stringify(response.data.user))
    window.location.href = "/dashboard";
  } catch (error) {
    console.log(error)
    alert("Wrong Username and Password")
  }
}
